﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web;
using FluentValidation;
using FluentValidation.Attributes;
using PicStore.Common;
using PicStore.Model;

namespace PicStore.Web.Models.Picture
{
    public class EditPictureModel
    {
        [Display(Name = "Picture Name")]
        public string PictureName { get; set; }
        public string PicturePath { get; set; }

        public int Id { get; set; }

        [Display(Name = "Take Photo Date")]
        public DateTime TakePhotoDate { get; set; }
        [Display(Name = "Upload Photo Date")]
        public DateTime UploadDate { get; set; }
        [Display(Name = "Upload User Name")]
        public string CreaterName { get; set; }

        public string Place { get; set; }
        public string Sex { get; set; }
        public string Item { get; set; }
        public string Color { get; set; }
        public string Style { get; set; }
        public string Length { get; set; }
        public string Collar { get; set; }
        public string Front { get; set; }
        public string Sleeve { get; set; }
        public string SweaterTexture { get; set; }
        public string Type { get; set; }

        [Display(Name = "Place")]
        public List<System.Web.Mvc.SelectListItem> PlaceList { get; set; }
        [Display(Name = "Sex")]
        public List<System.Web.Mvc.SelectListItem> SexList { get; set; }
        [Display(Name = "Item")]
        public List<System.Web.Mvc.SelectListItem> ItemList { get; set; }
        [Display(Name = "Color")]
        public List<System.Web.Mvc.SelectListItem> ColorList { get; set; }
        [Display(Name = "Style")]
        public List<System.Web.Mvc.SelectListItem> StyleList { get; set; }
        [Display(Name = "Length")]
        public List<System.Web.Mvc.SelectListItem> LengthList { get; set; }
        [Display(Name = "Collar")]
        public List<System.Web.Mvc.SelectListItem> CollarList { get; set; }
        [Display(Name = "Front")]
        public List<System.Web.Mvc.SelectListItem> FrontList { get; set; }
        [Display(Name = "Sleeve")]
        public List<System.Web.Mvc.SelectListItem> SleeveList { get; set; }
        [Display(Name = "SweaterTexture")]
        public List<System.Web.Mvc.SelectListItem> SweaterTextureList { get; set; }
        [Display(Name = "Type")]
        public List<System.Web.Mvc.SelectListItem> TypeList { get; set; }

        public bool IsValid { get; set; }
        public string ErrorMessage { get; set; }

        public static EditPictureModel BuildPictureModel(PictureInfo picture)
        {
            string pictureDomain = ConfigurationManager.AppSettings["PictureDomain"];

            var model = new EditPictureModel()
            {
                Id = picture.Id,
                PictureName = picture.PictureOnlyFileName,
                PicturePath = pictureDomain + picture.RelativePictureName,
                Place = picture.Place,
                Sex = picture.Sex,
                Item = picture.Item,
                Color = picture.Color,
                Style = picture.Style,
                Length = picture.Length,
                Collar = picture.Collar,
                Front = picture.Front,
                Sleeve = picture.Sleeve,
                SweaterTexture = picture.SweaterTexture,
                Type = picture.Type,
                TakePhotoDate = picture.TakePhotoDate,
                UploadDate = picture.CreateTime,
                CreaterName = picture.CreaterName,
            };

            return model;
        }

        public static PictureInfo BuildPictureByPictureModel(EditPictureModel picture)
        {
            var model = new PictureInfo() 
            {
                Id = picture.Id,
                Place = picture.Place,
                Sex = picture.Sex,
                Item = picture.Item,
                Color = picture.Color,
                Style = picture.Style,
                Length = picture.Length,
                Collar = picture.Collar,
                Front = picture.Front,
                Sleeve = picture.Sleeve,
                SweaterTexture = picture.SweaterTexture,
                Type = picture.Type,
            };

            return model;
        }
    }
}